package com.jeecms.wicool.manager.orders.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.orders.OrderProductMappingDao;
import com.jeecms.wicool.entity.orders.Orders;
import com.jeecms.wicool.entity.orders.OrderProductMapping;
import com.jeecms.wicool.manager.orders.OrdersMng;
import com.jeecms.wicool.manager.orders.OrderProductMappingMng;

@Service
@Transactional
public class OrderProductMappingMngImpl implements OrderProductMappingMng {
	
	private OrderProductMappingDao dao;
	@Autowired
	public void setDao(OrderProductMappingDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(Integer orderId,int pageNo, int pageSize) {
		Pagination page = dao.getPage(orderId,pageNo, pageSize);
		return page;
	}
	@Override
	public OrderProductMapping findById(Integer id) {
		OrderProductMapping entity = dao.findById(id);
		return entity;
	}

	
	@Override
	public List<OrderProductMapping> getAll() {
		return dao.getAll();
	}
	@Override
	public List<OrderProductMapping> getByOrderId(Integer OrderId) {
		return dao.getByOrderId(OrderId);
	}

	@Autowired
	private OrdersMng orderMng;

	@Override
	public OrderProductMapping update(OrderProductMapping bean,
			Integer orderId) {
		Orders order = orderMng.findById(orderId);
		bean.setDingdan(order);
		Updater<OrderProductMapping> updater = new Updater<OrderProductMapping>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

}